//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS KinesisVideoSignaling service.
///
/// Kinesis Video Streams Signaling Service is a intermediate service that establishes a communication channel for discovering peers, transmitting offers and answers in order to establish peer-to-peer connection in webRTC technology.
public struct KinesisVideoSignaling: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the KinesisVideoSignaling client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "KinesisVideoSignaling",
            serviceIdentifier: "kinesisvideo",
            serviceProtocol: .restjson,
            apiVersion: "2019-12-04",
            endpoint: endpoint,
            serviceEndpoints: Self.serviceEndpoints,
            variantEndpoints: Self.variantEndpoints,
            errorType: KinesisVideoSignalingErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }


    /// custom endpoints for regions
    static var serviceEndpoints: [String: String] {[
        "us-gov-east-1": "kinesisvideo-fips.us-gov-east-1.amazonaws.com",
        "us-gov-west-1": "kinesisvideo-fips.us-gov-west-1.amazonaws.com"
    ]}


    /// FIPS and dualstack endpoints
    static var variantEndpoints: [EndpointVariantType: AWSServiceConfig.EndpointVariant] {[
        [.fips]: .init(endpoints: [
            "us-gov-east-1": "kinesisvideo-fips.us-gov-east-1.amazonaws.com",
            "us-gov-west-1": "kinesisvideo-fips.us-gov-west-1.amazonaws.com"
        ])
    ]}

    // MARK: API Calls

    /// Gets the Interactive Connectivity Establishment (ICE) server configuration information, including URIs, username, and password which can be used to configure the WebRTC connection. The ICE component uses this configuration information to setup the WebRTC connection, including authenticating with the Traversal Using Relays around NAT (TURN) relay server.  TURN is a protocol that is used to improve the connectivity of peer-to-peer applications. By providing a cloud-based relay service, TURN ensures that a connection can be established even when one or more peers are incapable of a direct peer-to-peer connection. For more information, see A REST API For Access To TURN Services. You can invoke this API to establish a fallback mechanism in case either of the peers is unable to establish a direct peer-to-peer connection over a signaling channel. You must specify either a signaling channel ARN or the client ID in order to invoke this API.
    @Sendable
    @inlinable
    public func getIceServerConfig(_ input: GetIceServerConfigRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetIceServerConfigResponse {
        try await self.client.execute(
            operation: "GetIceServerConfig", 
            path: "/v1/get-ice-server-config", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Gets the Interactive Connectivity Establishment (ICE) server configuration information, including URIs, username, and password which can be used to configure the WebRTC connection. The ICE component uses this configuration information to setup the WebRTC connection, including authenticating with the Traversal Using Relays around NAT (TURN) relay server.  TURN is a protocol that is used to improve the connectivity of peer-to-peer applications. By providing a cloud-based relay service, TURN ensures that a connection can be established even when one or more peers are incapable of a direct peer-to-peer connection. For more information, see A REST API For Access To TURN Services. You can invoke this API to establish a fallback mechanism in case either of the peers is unable to establish a direct peer-to-peer connection over a signaling channel. You must specify either a signaling channel ARN or the client ID in order to invoke this API.
    ///
    /// Parameters:
    ///   - channelARN: The ARN of the signaling channel to be used for the peer-to-peer connection between configured peers.
    ///   - clientId: Unique identifier for the viewer. Must be unique within the signaling channel.
    ///   - service: Specifies the desired service. Currently, TURN is the only valid value.
    ///   - username: An optional user ID to be associated with the credentials.
    ///   - logger: Logger use during operation
    @inlinable
    public func getIceServerConfig(
        channelARN: String? = nil,
        clientId: String? = nil,
        service: Service? = nil,
        username: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetIceServerConfigResponse {
        let input = GetIceServerConfigRequest(
            channelARN: channelARN, 
            clientId: clientId, 
            service: service, 
            username: username
        )
        return try await self.getIceServerConfig(input, logger: logger)
    }

    /// This API allows you to connect WebRTC-enabled devices with Alexa display devices. When invoked, it sends the Alexa Session Description Protocol (SDP) offer to the master peer. The offer is delivered as soon as the master is connected to the specified signaling channel. This API returns the SDP answer from the connected master. If the master is not connected to the signaling channel, redelivery requests are made until the message expires.
    @Sendable
    @inlinable
    public func sendAlexaOfferToMaster(_ input: SendAlexaOfferToMasterRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> SendAlexaOfferToMasterResponse {
        try await self.client.execute(
            operation: "SendAlexaOfferToMaster", 
            path: "/v1/send-alexa-offer-to-master", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// This API allows you to connect WebRTC-enabled devices with Alexa display devices. When invoked, it sends the Alexa Session Description Protocol (SDP) offer to the master peer. The offer is delivered as soon as the master is connected to the specified signaling channel. This API returns the SDP answer from the connected master. If the master is not connected to the signaling channel, redelivery requests are made until the message expires.
    ///
    /// Parameters:
    ///   - channelARN: The ARN of the signaling channel by which Alexa and the master peer communicate.
    ///   - messagePayload: The base64-encoded SDP offer content.
    ///   - senderClientId: The unique identifier for the sender client.
    ///   - logger: Logger use during operation
    @inlinable
    public func sendAlexaOfferToMaster(
        channelARN: String? = nil,
        messagePayload: String? = nil,
        senderClientId: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> SendAlexaOfferToMasterResponse {
        let input = SendAlexaOfferToMasterRequest(
            channelARN: channelARN, 
            messagePayload: messagePayload, 
            senderClientId: senderClientId
        )
        return try await self.sendAlexaOfferToMaster(input, logger: logger)
    }
}

extension KinesisVideoSignaling {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: KinesisVideoSignaling, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}
